package com.neuedu.controller;

import com.alipay.api.AlipayApiException;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.neuedu.entity.PmsRegist;
import com.neuedu.entity.RegisterLevel;
import com.neuedu.entity.UmsDept;
import com.neuedu.entity.UmsDoctor;
import com.neuedu.service.*;
import com.neuedu.util.PayContent;
import com.neuedu.vo.ResultJson;
import jakarta.annotation.Resource;
import jakarta.servlet.http.HttpServletRequest;
import lombok.Getter;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.time.LocalDate;
import java.util.List;

/**
 * <p>
 * 挂号表 前端控制器
 * </p>
 *
 * @author 王禹
 * @since 2025-08-08
 */
@RestController
@RequestMapping("/pmsRegist")
public class PmsRegistController {
    @Resource
    UmsDeptService umsDeptService;
    @Resource
    UmsDoctorService umsDoctorService;
    @Resource
    PmsRegistService pmsRegistService;
    @Resource
    RegisterLevelService registerLevelService;
    @Resource
    PayService payService;

    @GetMapping("/list")
    ResultJson<List<PmsRegist>> list(Long open_id, LocalDate registDate, Byte active) {
        return ResultJson.success(pmsRegistService.list(open_id, registDate, active));
    }

    @GetMapping("/getDept")
    ResultJson<List<UmsDept>> getDept() {
        return ResultJson.success(umsDeptService.listForRegist());
    }
    @GetMapping("/getDoctor")
    ResultJson<List<UmsDoctor>> getDoctor(Long deptId) {
        return ResultJson.success(umsDoctorService.getRegistDoctor(deptId));
    }
    @GetMapping("/getRegisterLevel")
    ResultJson<List<RegisterLevel>> getRegisterLevel() {
        return ResultJson.success(registerLevelService.getRegisterLevelList());
    }
    @PostMapping("/add")
    ResultJson<String> add(PmsRegist pmsRegist, Long open_id) throws AlipayApiException, JsonProcessingException {
        return ResultJson.success(pmsRegistService.add(pmsRegist, open_id), "挂号成功");
    }
    @PostMapping("/pay")
    ResultJson<String> pay(PayContent payContent) throws AlipayApiException, JsonProcessingException {
        payContent.setSubject("挂号费");
        payContent.setProduct_code("FAST_INSTANT_TRADE_PAY");
        return ResultJson.success(payService.pay(payContent));
    }
}
